package com.tql.mall.common.handler;

import com.tql.mall.common.exception.MallException;
import com.tql.mall.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: tyk
 * @Date: 2023/5/20 20:33
 * @Description: 负责web模块的全局异常处理
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public  R error(Exception e) {
        e.printStackTrace();
        return R.fail();
    }

    /**
     * 自定义异常处理方法
     */
    @ExceptionHandler(MallException.class)
    @ResponseBody
    public R error(MallException e) {
        return R.fail().msg(e.getMessage());
    }
}
